#include "game.hpp"

Game::Game()
{
  screen=new Ecran();
  player=new Player();
  ship=new Vaisseau();
  menu=new Menu();

  menu->afficher_menu(screen);

  if(!(player->a_pseudo()))
    {
      string pseudo;
      cout << "Entrer votre pseudo : ";
      cin >> pseudo;
      player->set_pseudo(pseudo);
    }
  /*
  if(menu)
    delete menu;
  */
  in_run=true;
}

Game::~Game()
{
  if(player)
    delete player;

  if(menu)
    delete menu;

  if(ship)
    delete ship;
  
  if(screen)
    delete screen;
}

void Game::run()
{
  bool continu_p=false;
  bool continu_d=false;

  //  screen->peindre(0,0,800,800,255,255,255);
  //screen->afficher(10,10,ship->get_vaisseau()->get_face());

  while(in_run)
    {
      SDL_PollEvent(&event);

      switch(event.type)
	{
	case SDL_QUIT:
	  in_run=false;
	  break;

	case SDL_KEYDOWN:
	  switch(event.key.keysym.sym)
	    {
	    case SDLK_p:
	      continu_p=true;
	      break;

	    default:
	      break;
	    }
	  break;
	  
	case SDL_KEYUP:
	  switch(event.key.keysym.sym)
	    {
	    case SDLK_p:
	      continu_d=true;
	      break;
	      
	    default:
	      break;
	    }
	  break;

	default:
	  break;
	}

      if(continu_p && continu_d)
	{
	  continu_p=false;
	  continu_d=false;
	  player->add_continu();
	}

      screen->bouton();
      //cout << player->get_continu() << endl;

      screen->flip();
    }
}
